package com.dai.spec.gxk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dai.spec.common.utils.StringUtils;
import com.dai.spec.common.utils.bean.BeanUtils;
import com.dai.spec.gxk.domain.Student;
import com.dai.spec.gxk.mapper.CreditsMapper;
import com.dai.spec.gxk.service.CreditsService;
import com.dai.spec.gxk.vo.CreditsVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CreditsServiceImpl extends ServiceImpl<CreditsMapper, Student> implements CreditsService {


    /**
     * 分页查询所有学生学分
     *
     * @param student
     * @return
     */
    @Override
    public List<CreditsVO> queryCreditsList(Student student) {

        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotEmpty(student.getStudentNumber())) {
            queryWrapper.eq(Student::getStudentNumber, student.getStudentNumber());
        }
        if (StringUtils.isNotEmpty(student.getName())) {
            queryWrapper.like(Student::getName, student.getName());
        }
        List<Student> list = list(queryWrapper);
        List<CreditsVO> creditsVOList = list.stream().map(item -> {
            CreditsVO creditsVO = new CreditsVO();
            BeanUtils.copyBeanProp(creditsVO, item);
            return creditsVO;
        }).collect(Collectors.toList());

        return creditsVOList;
    }
}
